Page({
    data: {
        tabs: [{
                id: 0,
                value: "体验问题",
                isActive: true
            },
            {
                id: 1,
                value: "商品、商家投诉",
                isActive: false
            }
        ],
        chooseImage: [],
        textVal: ""
    },
    handleTabsItemChange(e) {
        //获取被点击的标题的索引
        console.log(e.detail);
        const {
            index
        } = e.detail;
        //修改原数组
        let {
            tabs
        } = this.data;
        tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false)
        this.setData({
            tabs
        })
    },

    handleChooseImg() {
        console.log(1111);
        wx.chooseImage({
            count: 9,
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            success: (res) => {
                console.log(res);
                this.setData({
                    chooseImage: [...this.data.chooseImage, ...res.tempFilePaths]
                })
            }
        })
    },
    handleRemoveImg(e) {
        const {
            index
        } = e.currentTarget.dataset
        let {
            chooseImage
        } = this.data
        chooseImage.splice(index, 1);
        this.setData({
            chooseImage,
        })
    },
    handleTextVal(e) {
        this.setData({
            textVal: e.detail.value
        })
    },
    handleFromSubmit() {
        const {
            textVal,
            chooseImage
        } = this.data;
        if (!textVal.trim()) {
            wx.showToast({
                title: '输入不合法',
                icon: 'none',
                mask: true,
            })
            return;
        }
        //准备上传图片到专门的图片服务器
        chooseImage.forEach((v,i) => {


            wx.uploadFile({
                //图片要上传到哪里
                url: "http://img.coolcr.cn/api/upload",
                filrPath: "v",
                name:"image",
                formData:{},
                success:(res)=>{
                    console.log(res);
                }
            })
        })
    }
})